<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();

if (empty($_SESSION['user_id'])) {
	include($_SERVER['DOCUMENT_ROOT'].'/portals/login.inc.php');
	exit;
}



include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');



$id = intval(@$_GET['id']);

$id = 111;

if ($id) {
	$current = getRow("SELECT * FROM portal WHERE portal_id = $id");
	
	if ($current['status_id'] != 1 ) { //TODO - || $current['user_id'] != $_SESSION['user_id']
		die("unable to edit this Portal");
	}
	
	$current['count'] = $count = count_active($id);

	
	print "<h3>Edit Current Portal</h3>";
} else {
	print "<h3>Add New Portal</h3>";
}

if (!empty($_POST)) {
die("not implemented yet");
	

}



if ($id) {
	print "<p>Editing Portal: <b>".he($current['title'])."</b>. <a href=\"portal.php?id=$id\">Return to listing</a> (without saving changes)</p>";
}

?>

<form method="post">

<h2>This is only a prototype -  can not save changes!</h2>

Layout: <select name="layout" disabled><option>Layout 1</option></select>

<p>Use the tickboxes below to select which components you wish to show on your portal homepage. The layout shown below roughly matches how it will be layed out on the page. </p>


<?

$is_admin = true;
include "homepages/linkspoty.php";



include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');



#####################


function description() {
	global $current;
	?>
		<input type="checkbox" checked /><b>{Full Description}</b><br/>
		<? echo he($current['description']);
}


function links_list() { ?>
		<input type="checkbox" checked /><b>{Selection of Links}</b>
		<ul>
		<?
		
		$links = array(
			'/?view=thumbs&order=added&in=d'=>'Recently added thumbnails',
			'/statistics.php'=>'Overview Statistics',
			'/breakdown.php'=>'By Year Breakdown',
			'/?opt=byyear4'=>'By Year Thumbnails',
			#'/?view=slide'=>'Slideshow',
			#'/?view=map'=>'Thumbnail Map',
			'/map.php'=>'Coverage Map',
			'/breakdown.php?by=category'=>'Category Breakdown',
			'/breakdown.php?view=cloud&by=category&order=count&in=d'=>'Category Word Cloud',
			#'/breakdown.php?view=text&by=realname&order=count&in=d'=>'Contributor Leaderboard',
			'/search.php'=>'Keyword Search',
			'/related.php'=>'Other Related Portals',
		);#''=>'',
			
		
		foreach ($links as $link => $title) {
			print "<li><input type=checkbox name=\"links[]\" value=\"".he($link)."\"  checked />";
			print "<a href=\"http://".he($current['domain']).".portal.geographs.org".he($link)."\" target=\"_blank\">".he($title)."</a>";
		}
		
		
		?>
		</ul>
<? } 

function featured_image() { 
	global $current;
	?>
		<input type="checkbox" checked /><b>{Featured Image}</b>
		
		<div style="padding:50px;border:1px solid silver;text-align:center">
			image id#: <br/>
			<input type="text" name="featured_id" value="<? echo he($current['featured_id']); ?>" size=8>
		</div>
<? }


function display_images() { 
	global $current; 
	?>
		<b>{Selection of images}</b>
		<ul>
		<?
		
		$links = array(
			'/?opt=byyear4'=>'By Year - 4 per year',
			'/?view=thumbs&order=added&in=d'=>'Recently added thumbnails',
			#'/?view=slide'=>'Slideshow',
			#'/?view=map'=>'Thumbnail Map',
			'/?view=thumbs2&opt=cluster'=>'4 per Automatic Cluster',
		);#''=>'',
			
		$checked = ($current['count'] > 1)?'/?view=thumbs&order=added&in=d':'/?opt=byyear4';
		
		foreach ($links as $link => $title) {
			print "<li><input type=radio name=\"homepage\" value=\"".he($link)."\"";
			if ($checked== $link) print "checked";
			print " /><a href=\"http://".he($current['domain']).".portal.geographs.org".he($link)."\" target=\"_blank\">".he($title)."</a>";

		}
				
		?>
		
		<li><input type=radio name="homepage" value="adv">Advanced<br/>
		<div class="d" style="float:left;width:200px">View style<br/><select name="view"><option value="listing">&middot; Full Listing</option><option value="thumbs" selected>&middot; Thumbnails</option><option value="thumbs2">&middot; Thumbnails2</option><option value="text">&middot; Plain-Text</option></select></div>
		<div class="d" style="float:left;width:200px">Order<br/><select name="order" ><option value="added" selected>Added</option><option value="taken">Date taken</option><option value="gridref">Grid Reference</option><option value="realname">Contributor Name</option><option value="title">Title</option><option value="category">Category</option><option value="y">South->North</option><option value="x">West->East</option><option value="submitted">Date submitted</option><option value="linear">Linear Order</option></select><select name="in" ><option value="a">Asc</option><option value="d" selected>Desc</option></select></div>
		<div class="d" style="float:left;width:200px">Option<br/><select name="opt"><option value="" selected>All</option><option value="byyear">Broken by Year</option><option value="byyear4">4 per Year</option><option value="categories">4 per Category</option><option value="users">4 per Contributor</option><option value="shared">4 per Shared Descriptions</option><option value="cluster">4 per Automatic Cluster</option><option value="linear">4 per Linear Group</option></select></div>
		<br style="clear:both"/>
		</li>
		
		</ul>
<? }

